package com.wxm.jwt.service.properties;

import com.wxm.jwt.util.RsaKeyHelper;

import java.security.PrivateKey;
import java.security.PublicKey;

/**
 * <p>
 *
 * </p>
 *
 * @author: wxm
 * @Date: 2021/10/6
 */
public interface JWTAuthService {
    /**
     * 获取公钥byte数组
     * @return byte[]
     */
    byte[] getAuthServicePubKey();

    /**
     * 获取私钥byte数组
     * @return byte[]
     */
    byte[] getAuthServicePriKey();

    /**
     * 获取到期秒数
     * @return int
     */
    int getExpireSecond();

    /**
     * 公钥字节数组转 PublicKey
     * @return PublicKey
     * @throws Exception
     */
    default PublicKey getPublicKey() throws Exception{
        return RsaKeyHelper.getPublicKey(this.getAuthServicePubKey());
    }

    /**
     * 私钥字节数组转 PrivateKey
     * @return PrivateKey
     * @throws Exception
     */
    default PrivateKey getPrivateKey() throws Exception{
        return RsaKeyHelper.getPrivateKey(this.getAuthServicePriKey());
    }
}
